﻿@using Microsoft.Extensions.Diagnostics.SmokeTests
@model List<RoutingGroup>

@functions {
    void Badge(string content, string color, bool condition = true, string? title = null)
    {
        if (condition)
        {
        <span class="badge badge-@color" title="@title">@content</span>
        }
    }
}

@{
    ViewData["Title"] = "Sitemaps";
}

<h2 class="mt-2 mb-3">@ViewData["Title"]</h2>

@foreach (var eds in Model!)
{
<h4>@eds.Name</h4>
<ul>
    @foreach (var ep in eds.Endpoints)
    {
    <li>
        @if (!ep.UsedForRouting)
        {
            Badge("non-route", "dark");
        }
        else
        {
            Badge(ep.Area + (!string.IsNullOrEmpty(ep.AlternativeName) || ep.Order != 0 ? " *" : ""), "light", ep.Area != null, (ep.AlternativeName != null ? "RouteName: " + ep.AlternativeName + "; " : "") + "Order: " + ep.Order);
            Badge("non-mvc" + (!string.IsNullOrEmpty(ep.AlternativeName) || ep.Order != 0 ? " *" : ""), "dark", ep.NonMvc, "Order: " + ep.Order);
            if (!ep.Inert)
            {
                var methods = ep.AllowedMethods ?? Array.Empty<string>();
                Badge("GET", "primary", methods.Contains("GET"));
                Badge("POST", "success", methods.Contains("POST"));
                Badge("PUT", "warning", methods.Contains("PUT"));
                Badge("DELETE", "danger", methods.Contains("DELETE"));
                Badge("PATCH", "info", methods.Contains("PATCH"));
                Badge("OPTIONS", "dark", methods.Contains("OPTIONS"));
                Badge("HEAD", "dark", methods.Contains("HEAD"));
                Badge("TRACE", "dark", methods.Contains("TRACE"));
                Badge("CONNECT", "dark", methods.Contains("CONNECT"));
        <code>@ep.RoutePattern</code>
            }
            else
            {
                Badge("inert", "secondary");
            }
        }
        @ep.Description
    </li>
    }
</ul>
}
